package com.fzhucc.modules.lesson.rest;

import com.fzhucc.annotation.Log;
import com.fzhucc.modules.lesson.domain.dto.LessonLearnRecordAddDto;
import com.fzhucc.modules.lesson.domain.dto.LessonLearnRecordQueryCriteria;
import com.fzhucc.modules.lesson.service.LessonLearnRecordService;
import com.fzhucc.modules.sciPersonnelInfo.domain.dto.SciPersonnelInfoQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* @author yyg
* @date 2022-12-08
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "课程:学习记录管理")
@RequestMapping("/api/lessonLearnRecord")
public class LessonLearnRecordController {

    private final LessonLearnRecordService lessonLearnRecordService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('lessonLearnRecord:list')")
    public void exportLessonLearnRecord(HttpServletResponse response, LessonLearnRecordQueryCriteria criteria) throws IOException {
        lessonLearnRecordService.download(lessonLearnRecordService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询lessonLearnRecord")
    @ApiOperation("查询lessonLearnRecord")
    @PreAuthorize("@el.check('lessonLearnRecord:list')")
    public ResponseEntity<Object> queryLessonLearnRecord(LessonLearnRecordQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(lessonLearnRecordService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增学习记录接口 在线用户视频播放完成后调用")
    @ApiOperation("新增学习记录接口 在线用户视频播放完成后调用")
    public ResponseEntity<Object> createLessonLearnRecord(@Validated @RequestBody LessonLearnRecordAddDto resources){
        return new ResponseEntity<>(lessonLearnRecordService.create(resources),HttpStatus.CREATED);
    }


    @PostMapping(value = "/getLessonLearnRecordByMe")
    @Log("我的课程学习记录情况")
    @ApiOperation("我的课程学习记录情况")
    public ResponseEntity<Object> getLessonLearnRecordByMe(){
        return new ResponseEntity<>(lessonLearnRecordService.getLessonLearnRecordByMe(),HttpStatus.OK);
    }


    @GetMapping(value = "/my")
    @Log("我的课程学习记录分页")
    @ApiOperation("我的课程学习记录分页")
    public ResponseEntity<Object> my(LessonLearnRecordQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(lessonLearnRecordService.my(criteria,pageable), HttpStatus.OK);
    }

}